package statistics;
//import edu.rit.numeric.Statistics;

public class ChiSquareTests extends AbstractStatisticTests {
//
//	private double slope = 1;
//	private double intercept = 1;
//	
//	public ChiSquareTests() {
//	};
//			
//	public ChiSquareTests(double slope, double intercept) {
//		this();
//		this.slope = slope;
//		this.intercept = intercept;
//	}
//	
//	public int[][][] correctedExpectations(int order, int[][][] expectedCases, int[][][] expectedControls, int[][][] observedControls) {
//		int[][][] expectedCasesAfterCorrection = new int[2][2][2];
//		
//		if( order == 2 ) {
//			for(int j=0; j<2; j++) { 
//				for(int k=0; k<2; k++) { 
//					expectedCasesAfterCorrection[1][j][k] = (int) Math.round ( ((double) observedControls[1][j][k] / expectedControls[1][j][k]) * expectedCases[1][j][k] );
//				}
//			}
//		}
//		
//		else if (order == 3) {
//			for(int i=0; i<2; i++) {
//				for(int j=0; j<2; j++) { 
//					for(int k=0; k<2; k++) { 
//						expectedCasesAfterCorrection[i][j][k] = (int) Math.round ( ((double) observedControls[i][j][k] / expectedControls[i][j][k]) * expectedCases[i][j][k] );
//					}
//				}
//			}
//		}
//		
//		return expectedCasesAfterCorrection;
//	}
//
//	
//	@Override
//	public double TestCasesOnly ( int order, double[][][] expectedCases, int[][][] observedCases, int totalCases ) { 
//		expectedCases = bayesianCorrection(order, expectedCases);
//		
//		double[] expected = makeSingleArray(expectedCases, order);
//		double[] observed = makeSingleArray(observedCases, order);
//		
//		double chiSqStat = 0;
//		for(int i=0; i<expected.length; i++) {
//			chiSqStat += Math.pow(observed[i] - expected[i],2) / expected[i];
//		}
//			
//		double pvalue = 1;
//		if ( order == 2 ) {
//			pvalue = Statistics.chiSquarePvalue(1, chiSqStat); 
//		}
//		else if ( order == 3 ) {//4 d.o.f. but TBD in a model specific manner.
//			pvalue = Statistics.chiSquarePvalue(4, chiSqStat); 
//		}
//		return AnovaCorrection(pvalue);	
//	}
//	
//	
//	@Override
//	public double TestCasesVsControls ( int order,
//			double[][][] expectedCases, int[][][] observedCases, int totalCases,
//			double[][][] expectedControls, int[][][] observedControls, int totalControls ) { 
//		
//		//make sure there are no zeros
//		expectedControls = bayesianCorrection(order, expectedControls);
//		expectedCases = bayesianCorrection(order, expectedCases);
//		
//		//change expectations of cases to reflect controls.
//		int[][][] expectedCasesAfterCorrection = correctedExpectations(order, expectedCases, expectedControls, observedControls);
//		
//		//calculate the interaction chisq pvalue
//		double pvalueInteraction = TestCasesOnly(order, expectedCasesAfterCorrection, observedCases, totalCases);
//		
//		//correct based on regression of chi sq wrt anova.
//		return AnovaCorrection (pvalueInteraction);
//	}
//	
//	
//	//Regression correction
//	public double AnovaCorrection (double pvalue) {
//		
//		//Regressed y = mx + c  on the log scale -----  
//		// -log(p_anova) = m*-log(p_chisq) + c
//		// => 1/p_anova = 1/(p_chisq^m) * 10^c
//		// => p_anova = (p_chisq)^m / 10^c;
//		
//		double pvalueInteractionCorrected = Math.pow(pvalue, slope) / Math.pow(10, intercept);
//		
//		return pvalueInteractionCorrected;
//	}
	
	
}

